module Webots

using Libdl

function __init__()
    path = joinpath([ENV["WEBOTS_HOME"], "lib", "controller"])
    lib = @static Sys.iswindows() ? "Controller.dll" : "libController.so"
    global lib = joinpath(path, lib)
end

struct WbDeviceTag end

export AbstractDevice, Device
export init, cleanup
export basictimestep, wbstep, enable, disable, step_begin, step_end
export Motor, set_position, set_velocity, set_acceleration, set_available_force, set_available_torque,
    set_control_pid, target_position, min_position, max_position, velocity,
    max_velocity, acceleration, available_force, max_force, available_torque,
    max_torque, multiplier, enable_force_feedback, disable_force_feedback, force_feedback,
    force_feedback_sampling_period, enable_torque_feedback, disable_torque_feedback,
    torque_feedback, torque_feedback_sampling_period,
    battery, battery_enable, battery_disable, battery_sampling_period
export Imu, rollpitchyaw
export GPS, altitude
export Gyro, accelerations
export DistanceSensor, maxvalue, minvalue, distance, sensortype


include("world.jl")
include("device.jl")
include("devices/gps.jl")
include("devices/imu.jl")
include("devices/gyro.jl")
include("devices/motor.jl")
include("devices/camera.jl")
include("devices/robot.jl")
include("devices/distance.jl")

function init()
    @ccall lib.wb_robot_init()::Cvoid
end

function cleanup()
    @ccall lib.wb_robot_cleanup()::Cvoid
end

step_begin(duration) = @ccall lib.wb_robot_step_begin(duration::Cint)::Cint
step_end() = @ccall lib.wb_robot_step_end()::Cint

end # module Webots
